package com.ylbh.modules.returntemplate.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.utils.*;
import com.ylbh.modules.returntemplate.entity.ShoppingApplySpeechBundle;
import com.ylbh.modules.returntemplate.service.ShoppingApplySpeechBundleService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 退换货模板
 * @author czx
 */
@RestController
@RequestMapping("return")
public class ShoppingApplySpeechBundleController {

    @Autowired
    private ShoppingApplySpeechBundleService shoppingApplySpeechBundleService;

    @RequestMapping("queryReturnTemplate")
    @RequiresPermissions("return:queryReturnTemplate")
    @ApiOperation("退换货模板列表")
    public CommonResult<PageUtils> queryReturnTemplate(PageDTO pageDTO) {
        PageUtils list = shoppingApplySpeechBundleService.queryReturnTemplate(pageDTO);
        return Ref.ok(list);
    }

    @RequestMapping("getReturnTemplate/{id}")
    @RequiresPermissions("return:getReturnTemplate")
    @ApiOperation("退换货模板列表")
    public CommonResult<ShoppingApplySpeechBundle> getReturnTemplate(@PathVariable Long id) {
        ShoppingApplySpeechBundle vo = shoppingApplySpeechBundleService.getById(id);
        return Ref.ok(vo);
    }

    @SysLog("新增退换货模板")
    @RequestMapping("addReturnTemplate")
    @RequiresPermissions("return:addReturnTemplate")
    @ApiOperation("新增退换货模板")
    public CommonResult<Void> addReturnTemplate(@RequestBody ShoppingApplySpeechBundle dto) {
        dto.setCreateUserId(ShiroUtils.getUserId().intValue());
        dto.setCreateTime(new Date());
        shoppingApplySpeechBundleService.save(dto);
        return Ref.ok();
    }

    @SysLog("修改退换货模板")
    @RequestMapping("modifyReturnTemplate")
    @RequiresPermissions("return:modifyReturnTemplate")
    @ApiOperation("修改退换货模板")
    public CommonResult<Void> modifyReturnTemplate(@RequestBody ShoppingApplySpeechBundle dto) {
        dto.setCreateUserId(ShiroUtils.getUserId().intValue());
        dto.setCreateTime(new Date());
        shoppingApplySpeechBundleService.updateById(dto);
        return Ref.ok();
    }

    @SysLog("修改退换货模板显示状态")
    @RequestMapping("modifyReturnTemplateState")
    @ApiOperation("修改退换货模板显示状态")
    public CommonResult<Void> modifyReturnTemplateState(@RequestBody ShoppingApplySpeechBundle dto) {
        dto.setCreateUserId(ShiroUtils.getUserId().intValue());
        dto.setCreateTime(new Date());
        shoppingApplySpeechBundleService.updateById(dto);
        return Ref.ok();
    }


}
